﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Sales_SalesStatis : ATPages
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        lblPath.Text = f.getModuleidAdd(Request["moduid"]);
        txtKdate.Attributes.Add("onclick", "SelectDate('txtKdate')");
        txtJdate.Attributes.Add("onclick", "SelectDate('txtJdate')");
        if (!IsPostBack)
        {
            initKdate();
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        ZSql zs = new ZSql();
        string sql = "select  comodid ,comodName,modul,unit,sum(number)as number1,sum(TotalMoney) as TotalMoney1  from CS_Sales where 1=1 ";

        if (!string.IsNullOrEmpty(txtSalesCode.Text))
        {
            sql += " and comodid='" + txtSalesCode.Text + "'";
        }
        if (!string.IsNullOrEmpty(txtGuest.Text))
        {
            sql += " and comodName like '" + txtGuest.Text + "%'";
        }
        if (!string.IsNullOrEmpty(txtKdate.Text) && !string.IsNullOrEmpty(txtJdate.Text.Trim()))
        {
            sql += " and C_date >='" + txtKdate.Text + " 00:00:00' and C_date<='" + txtJdate.Text + " 23:59:59'";
        }
        sql += "  group by comodid ,comodName,modul,unit";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }

    private void initKdate()
    {
        txtJdate.Text = DateTime.Now.ToShortDateString();

        int month = DateTime.Now.Month - 1;
        string m = "";
        if (month < 10)
        {
            m = "0" + month.ToString(); ;
        }
        else
        {
            m = month.ToString();
        }

        txtKdate.Text = DateTime.Now.Year.ToString() + "-" + m + "-" + DateTime.Now.Day;
    }
}
